package other;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

// 坐标
public class CoordinateDemo extends Application {
	private Pane root = new Pane();
	private Pane pane = new Pane();
	private Button button;
	
	public static void main(String[] args) {
		launch(args);
	}
	
	@Override
	public void start(Stage stage) throws Exception {
		
		pane.setPrefSize(300, 300);
		pane.setStyle("-fx-background-color: pink");
		pane.setLayoutX(100);
		pane.setLayoutY(100);
		
		button = new Button("哈哈");
		button.setScaleX(2);
		button.setLayoutX(100);		// setX与setLayoutX的区别
		button.setLayoutY(100);
		pane.getChildren().add(button);
		
		root.getChildren().add(pane);
		
		Scene scene = new Scene(root, 400, 400);
		stage.setScene(scene);
		stage.show();
		
		// 事件
		// 输出相对于所处布局的位置
		System.out.println(button.getLocalToParentTransform().getTx() + "  " + button.getLocalToParentTransform().getTy());
		// 输出相对于窗口场景的位置
		System.out.println(button.getLocalToSceneTransform().getTx() + "  " + button.getLocalToSceneTransform().getTy());
	}
}
